package com.flying.srccode;

import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.TreeSet;

/**
 * @ClassName TreeSetSrc
 * @Author flying
 * @Date 2025/2/3 8:11
 * @Description TreeSet源码分析
 */
public class TreeSetSrc {

    @Test
    void test1(){

        /**
         * HashSet的成员变量
         *     private transient HashMap<E,Object> map;
         *     private static final Object PRESENT = new Object();   // 用于Map中的Value站位
         */


        /**
         *     public HashSet() {
         *         map = new HashMap<>();
         *     }
         */
        HashSet<String> hashSet=new HashSet<>();


        /**
         *     public boolean add(E e) {
         *         return map.put(e, PRESENT)==null;
         *     }
         *
         *     public V put(K key, V value) {     // 调用HashMap的方法
         *         return putVal(hash(key), key, value, false, true);  // 细节在HashMap中分析
         *     }
         */
        hashSet.add("a");




    }



    @Test
    void test2(){
        /**
         * private transient NavigableMap<E,Object> m;
         * private static final Object PRESENT = new Object();
         */


        /**
         *     public TreeSet() {
         *         this(new TreeMap<>());
         *     }
         *
         *
         *     public TreeSet(Comparator<? super E> comparator) {
         *         this(new TreeMap<>(comparator));
         *     }
         */

        TreeSet<String>  treeSet=new TreeSet<>();


        /**
         *     public boolean add(E e) {
         *         return m.put(e, PRESENT)==null;
         *     }
         */
        treeSet.add("a");










    }

}
